// 处理 与 用户相关的 接口

// 手动导入 配置好的 axios
import axios from '@/utils/request.js'

// 上传图片
export const uploadPhoto = function (fd) {
    return axios({
        method: 'PATCH',
        url: '/v1_0/user/photo',
        data: fd
    })
}

// 修改用户信息
export const editUser = function ({ name, gender, birthday, intro }) {
    return axios({
        method: 'PATCH',
        url: '/v1_0/user/profile',
        data: {
            name, gender, birthday, intro
        }
    })
}

// 0.导出 查询个人用户信息接口
export const getProfile = function () {
    return axios({
        url: '/v1_0/user/profile'
    })
}

// 0.导出更新token接口
export const getNewToken = function (refreshToken) {
    console.log('refreshToken->', refreshToken)
    return axios({
        url: '/v1_0/authorizations',
        method: 'put',
        headers: {
            Authorization: 'Bearer ' + refreshToken
        }
    })
}

// 【按需导出】 不同的 接口请求方法----------------
// 1.导出 登录接口
export const login = function (mobile, code) {
    // 返回 axios 创建的 Promise对象
    return axios({
        method: 'post',
        url: '/v1_0/authorizations',
        data: {
            mobile,
            code
        }
    })
}

// 2.导出 发送验证码接口
export const sendSMS = function (mobile) {
    return axios({
        method: 'get',
        url: `/v1_0/sms/codes/${mobile}`
    })
}

// 3.获取用户数据
export const getUserInfo = function () {
    return axios({
        url: '/v1_0/user',
        method: 'get',
        // headers: { 'Authorization': 'Bearer ' + usrToken },
    })
}

// 4.获取用户频道列表数据
export const getUserChannels = function () {
    return axios({
        method: 'get',
        url: '/v1_0/user/channels'
    })
}

// 5.添加关注用户
export const addFollow = function (targetid) {
    return axios({
        url: '/v1_0/user/followings',
        method: 'post',
        data: {
            target: targetid
        }
    })
}

// 6.取消关注用户
export const delFollow = function (targetid) {
    return axios({
        url: `/v1_0/user/followings/${targetid}`,
        method: 'delete'
    })
}